package com.yc.hwc.biz;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import org.springframework.validation.Errors;

import com.yc.hwc.bean.User;
import com.yc.hwc.dao.IUserExDao;

@Service
public class UserBiz extends BaseBiz<User> {

	public void setDao(JpaRepository<User, Long> dao) {
		// 废弃;
	}

	@Autowired
	public void setDao(IUserExDao dao) {
		this.dao = dao;
	}

	@Override
	protected boolean mysave(User e, Errors es) throws BizException {
		String[] names = null;
		if (e.getId() == null && e.getAccount() == null && e.getName() != null) {
			e.setName(e.getName().replaceAll("\\s+", ""));
			names = e.getName().split("[,.;:，。；：]");
		}
		if (names == null || names.length <= 1) {
			return super.mysave(e, es);
		} else {
			for (String name : names) {
				User u = new User();
				u.setName(name);
				u.setAccount(name);
				u.setPwd("123456");
				u.setClsSn(e.getClsSn());
				u.setRole((byte) 1);
				dao.save(u);
			}
			return false;
		}
	}

}
